#!/bin/bash
#==============================================================================
# Copyright 2014 zod.yslin
# Author: zod.yslin
# Email:
# File Name: netstat.sh
# Description:
#   The netstat utility tells us that some process is using a
#   particular port or address, but it doesn’t tell us which process.
#
#   There are four types of information available:
#   1. Active Sockets
#   2. Interfaces
#   3. Routing Table
#   4. Protocol Statistics
# Edit History:
#   2014-12-30    File created.
#==============================================================================
#==============================================================================
# 1. Active Sockets
#==============================================================================
# TCP/UDP sockets
netstat -a --inet
#==============================================================================
# 2. Interfaces
#==============================================================================
# the basic interface information
netstat -i
#==============================================================================
# 3. Routing Table
#==============================================================================
# -n option to request numbers instead of names for IP addresses
netstat -rn
# The fourth column displays various flags that describe the route:
# G The route uses a gateway. 
# G The route is indirect. That is, the destination is not connected directly
#   but must be reached through an intermediate router or gateway (hence G).
# U The interface to be used is up. 
# H Only a single host can be reached through the route. For example, this is
#   the case for the loopback entry 127.0.0.1. 
# H This is a route to a host. If this flag is not present, the route is to a
#   network (or possibly a subnetwork if CIDR (Tip 2) is not in use).
# D This is set if the table entry has been generated by an ICMP redirect
#   message (see section 3.5). 
# M This is set if the table entry was modified by an ICMP redi- rect message. 
#==============================================================================
# 4. Protocol Statistics
#==============================================================================
# tcp
netstat -s -t
# udp
netstat -s -u
# raw
netstat -s -w
